package org.jeecg.modules.activity.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xkcoding.http.util.StringUtil;
import org.jeecg.modules.activity.entity.ActivityInfo;
import org.jeecg.modules.activity.entity.ConActivityApplyItem;
import org.jeecg.modules.activity.entity.ConActivityApplyItemValue;
import org.jeecg.modules.activity.mapper.ConActivityApplyItemMapper;
import org.jeecg.modules.activity.mapper.ConActivityApplyItemValueMapper;
import org.jeecg.modules.activity.service.IActivityInfoService;
import org.jeecg.modules.activity.service.IConActivityApplyItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 活动报名选项
 * @Author: jeecg-boot
 * @Date:   2020-05-02
 * @Version: V1.0
 */
@Service
public class ConActivityApplyItemServiceImpl extends ServiceImpl<ConActivityApplyItemMapper, ConActivityApplyItem> implements IConActivityApplyItemService {


    @Autowired
    private IActivityInfoService activityInfoService;

    @Autowired
    private ConActivityApplyItemMapper activityApplyItemMapper;
    @Autowired
    private ConActivityApplyItemValueMapper activityApplyItemValueMapper;

    @Override
    public List<ConActivityApplyItem> getApplyInfo(String taskNo) {

        QueryWrapper<ActivityInfo> activityInfoQueryWrapper = new QueryWrapper<>();
        activityInfoQueryWrapper.eq("task_id",taskNo).last(" limit 1");
        ActivityInfo activityInfo =  activityInfoService.getOne(activityInfoQueryWrapper);
        // 查询报名选项
        List<ConActivityApplyItem> applyItemList = activityApplyItemMapper.selectList(
                new QueryWrapper<ConActivityApplyItem>()
                        .eq("activity_id", activityInfo.getActivityNo())
                        .eq("del_flag", "0"));
        // 查询选项值
        if(null != applyItemList && applyItemList.size() > 0) {
            for(ConActivityApplyItem item:applyItemList) {
                List<ConActivityApplyItemValue> itemValueList = activityApplyItemValueMapper.selectList(new QueryWrapper<ConActivityApplyItemValue>()
                        .eq("item_id", item.getId())
                        .eq("del_flag", "0"));
                item.setItemValueList(itemValueList);
            }
        }
        return applyItemList;
    }
}
